package Clock;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Connor Madden.
 * User: Connor Madden
 * Date: 12/10/11
 * Time: 8:16 PM
 */
public class ClockFactory {
    private static ClockFactory ourInstance = new ClockFactory();
    private Map<Object, ClockI> clocks;

    private static ClockFactory getInstance() {
        return ourInstance;
    }

    private ClockFactory() {
        clocks = new HashMap<Object, ClockI>();
    }

    public static ClockI getClock(long t) {
        return new Clock(t);
    }

    public static ClockI getClock(Object obj) {
        ClockFactory clockFactory = getInstance();
        if (clockFactory.clocks.containsKey(obj)) {
            return clockFactory.clocks.get(obj);
        } else {
            return null;
        }
    }

    public static ClockI getClock(long t, Object obj) {
        ClockFactory clockFactory = getInstance();
        if (clockFactory.clocks.containsKey(obj)) {
            return clockFactory.clocks.get(obj);
        } else {
            ClockI newClock = new Clock(t);
            clockFactory.clocks.put(obj, newClock);
            return newClock;
        }
    }
}
